package com.example.demo.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.google.gson.Gson;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;


/**
 * Created at 2021/3/5 2:37 下午
 *
 * @author Alex
 * description
 */
@Component
@Slf4j
public class AliPayConfig {
    @Value("${alipay.gatewayUrl}")
    private String serverUrl;

    @Value("${alipay.app_id}")
    private String appId;

    @Value("${alipay.alipay_public_key}")
    private String publicKey;

    @Value("${alipay.merchant_private_key}")
    private String privateKey;

    @Bean
    public DefaultAlipayClient getAlipayClient() {
        java.security.Security.addProvider(
                new org.bouncycastle.jce.provider.BouncyCastleProvider()
        );
        return new DefaultAlipayClient(serverUrl, appId, privateKey, "json", "UTF-8", publicKey, "RSA2");
    }

    @Bean
    public Gson getDefaultGson() {
        return new Gson();
    }

}
